﻿#include "vofa+.h"
#include "PWM.h"
#include "speed_reading.h"
#include "USART1_DMA.h"

uint8_t tail[4] = {0x00, 0x00, 0x80, 0x7f};	//结束数组
uint8_t c_data[4];//存放转化后char数�
void float_turn_u8(float f,uint8_t * c)
{
	uint8_t x;
	FloatLongType data;
	data.fdata=f;
	for(x=0;x<5;x++){
	c[x]=(uint8_t)(data.ldata>>(x*8));
	}
}

//fdata:float数据数组 fdata_num：float数组数据个数/通道个数 Usart_choose：选择发送的串口
void JustFloat_Send(float * fdata,uint16_t fdata_num,USART_TypeDef *Usart_choose){
	uint16_t x;
	uint8_t y;
		for(x=0;x<fdata_num;x++){
			float_turn_u8(fdata[x],c_data);
			for(y=0;y<4;y++){
				Usart_choose->DR=c_data[y];
				while((Usart_choose->SR&0X40)==0);//等待发送结束
			}
		}
		for(y=0;y<4;y++){//发送结束数组
				Usart_choose->DR=tail[y];
			while((Usart_choose->SR&0X40)==0);//等待发送结束
		}
}

void JustFloat_M2PSend(float * fdata,uint16_t fdata_num)
{
	uint16_t x;
	uint8_t y;
		for(x=0;x<fdata_num;x++)
		{
			float_turn_u8(fdata[x],c_data);
			DMA_USART1_Tx_Data(c_data, 4);
		}

		for(y=0;y<4;y++)
		{//发送结束数组
			DMA_USART1_Tx_Data(tail, 4);
		}
}

